package com.yudaob2b.elong.listener.aliyun.mq;

import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.yudaob2b.business.constant.AliyunConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.Properties;

/**
 * @Author: Kidd.Tan
 * @Description
 * @Date: Create in 16:02 2018/7/5
 */
public class MyMessageConsumer {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private static final String CONSUMER_ID = "CID_ELONGHOTEL"; //你申请的ConsumerId
    private static final String ONS_Addr = "http://onsaddr-internet.aliyun.com/rocketmq/nsaddr4client-internet"; //你申请的ConsumerId

    /**
     * 订阅消息
     */
    public void subscribe() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.ConsumerId, CONSUMER_ID);
        properties.put(PropertyKeyConst.AccessKey, AliyunConstant.ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, AliyunConstant.SECRET_KEY);
        properties.put(PropertyKeyConst.ONSAddr, ONS_Addr);
        Consumer consumer = ONSFactory.createConsumer(properties);
        consumer.subscribe(AliyunConstant.TOPIC_INCR_INV_NAME, "*", new MyMessageListener());
        consumer.start();
        logger.info(CONSUMER_ID + " is running @" + new Date());
    }

}
